def parse_institues():
    from BeautifulSoup import BeautifulSoup,SoupStrainer
    import pymongo
    from pymongo import Connection
    conn = Connection('localhost:27017,localhost:27018,localhost:27019') 
    db = conn['promise'] 
    for x in db.institues.find(): print x
    #db.institues.remove({})
    page = open('jigou.html','r')
    soup = BeautifulSoup(page,parseOnlyThese=SoupStrainer('img'))
    for e in soup:  
        if e['alt'] == '':
            continue
        image, name = '%s.gif'%(e['src'][-11:]), e['alt']
        #db.institues.save({'name': name, 'image': image}) 
 

def rename(dir, pattern, titlePattern):
    for pathAndFilename in glob.iglob(os.path.join(dir, pattern)):
        title, ext = os.path.splitext(os.path.basename(pathAndFilename))
        os.rename(pathAndFilename,os.path.join(dir, titlePattern % title + ext))
        
def modify_images():
    import glob, os 
    dir = '/apps/workspace/static/promise/img/institute'
    for name in os.listdir(dir):
        filename = '%s/%s'%(dir,name) 
        os.rename(filename,'%s.gif'%filename)
         